﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Design;
using Asol.Reporting.Editor.Components;
using Asol.Reporting.Support.Components;

namespace Asol.Reporting.Editor.Editor
{
    #region class EditorPropertyPanel : potomek Panel, obsahující PropertyGrid a ComboBox
    /// <summary>
    /// EditorPropertyPanel : potomek Panel, obsahující PropertyGrid a ComboBox
    /// </summary>
    public class EditorPropertyPanel : Panel
    {
        #region Konstrukce
        /// <summary>
        /// Konstruktor
        /// </summary>
        public EditorPropertyPanel()
        {
            this.Initialize();
        }
        private void Initialize()
        {
            this._PropertyGrid = new EditorPropertyGrid();
            this._PropertyGrid.Dock = DockStyle.Fill;
            this.Controls.Add(this._PropertyGrid);

            this._ObjectCombo = new DComboBox();
            this._ObjectCombo.DropDownStyle = ComboBoxStyle.DropDownList;
            this._ObjectCombo.FlatStyle = FlatStyle.Popup;
            this._ObjectCombo.BackColor = System.Drawing.SystemColors.ControlLight;
            this._ObjectCombo.MaxDropDownItems = 23;
            this._ObjectCombo.Location = new System.Drawing.Point(0, 0);
            this._ObjectCombo.Dock = DockStyle.Top;
            this.Controls.Add(this._ObjectCombo);
        }
        private EditorPropertyGrid _PropertyGrid;
        private DComboBox _ObjectCombo;
        #endregion
        #region Transparentní property a eventy: Z Panelu přímo do privátních controlů
        /// <summary>
        /// Gets or sets a value indicating whether the commands pane is visible for objects that expose verbs.
        /// </summary>
        public bool CommandsVisibleIfAvailable { get { return this._PropertyGrid.CommandsVisibleIfAvailable; } set { this._PropertyGrid.CommandsVisibleIfAvailable = value; } }
        /// <summary>
        /// Gets or sets the object for which the grid displays properties.
        /// </summary>
        public object SelectedObject { get { return this._PropertyGrid.SelectedObject; } set { this._PropertyGrid.SelectedObject = value; } }
        /// <summary>
        /// Gets or sets the currently selected objects.
        /// </summary>
        public object[] SelectedObjects { get { return this._PropertyGrid.SelectedObjects; } set { this._PropertyGrid.SelectedObjects = value; } }
        /// <summary>
        /// Occurs when the selected System.Windows.Forms.GridItem is changed.
        /// </summary>
        public event SelectedGridItemChangedEventHandler SelectedGridItemChanged { add { this._PropertyGrid.SelectedGridItemChanged += value; } remove { this._PropertyGrid.SelectedGridItemChanged -= value; } }
        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyValueChangedEventHandler PropertyValueChanged { add { this._PropertyGrid.PropertyValueChanged += value; } remove { this._PropertyGrid.PropertyValueChanged -= value; } }
        /// <summary>
        /// Položky v nabídce objektů editoru
        /// </summary>
        [Browsable(false)]
        public IEnumerable<DComboItem> ComboDItems { get { return this._ObjectCombo.DItems; } set { this._ObjectCombo.DItems = value; } }
        /// <summary>
        /// Aktuálně vybraný objekt (položka) v nabídce objektů editoru
        /// </summary>
        [Browsable(false)]
        public DComboItem ComboSelectedDItem { get { return this._ObjectCombo.SelectedDItem; } set { this._ObjectCombo.SelectedDItem = value; } }
        /// <summary>
        /// Metoda najde v položkách Combo boxu objekt s daným ID
        /// </summary>
        /// <param name="findID"></param>
        /// <returns></returns>
        public DComboItem ComboFindDItem(IComparable findID)
        {
            return this._ObjectCombo.ComboFindDItem(findID);
        }
        /// <summary>
        /// Událost po změně vybraného objektu v nabídce objektů editoru
        /// </summary>
        public event EventHandler ComboSelectedIndexChanged { add { this._ObjectCombo.SelectedIndexChanged += value; } remove { this._ObjectCombo.SelectedIndexChanged -= value; } }
        #endregion
    }
    #endregion
    #region class EditorPropertyGrid : potomek PropertyGrid pro vnitřní používání
    /// <summary>
    /// EditorPropertyGrid : potomek PropertyGrid pro vnitřní používání
    /// </summary>
    public class EditorPropertyGrid : PropertyGrid
    { }
    #endregion
}
